﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Csharp__练习总结
{
    //静态列表
    class MonsterManage 
    {
        public static List<Monster> monsterList = new List<Monster>();
        public static Random r = new Random();//静态骰子---哥布林和怪物的攻击力不一样---可以排序


    }
        

    //比较
    class Monster:IComparable<Monster>
    {
        public string name;
        public int attack;

        public Monster(string name) 
        {
            this.name = name;

            //添加到静态列表
            MonsterManage.monsterList.Add(this);//添加自己
        }

        //虚方法
        public virtual void Attack() { }

        //实现接口----可以进行比较
        public int CompareTo(Monster other)
        {
            if (this.attack > other.attack)
            {
                return 1;
            }
            else 
            {
                return -1;
            }
        }

        public override string ToString()
        {
            //Format 字符串格式化
            return String.Format("{0}:攻击力{1}", name, attack);
            //打印monster的时候就会打印这句话
        }




    }


    class Gablin:Monster
    {
        //继承后构造函数
        public Gablin(string name) : base(name)
        {
            attack = MonsterManage.r.Next(100, 201);//name传参到monster去了，这里执行的是自己的attack的方法
        }
        
        //override 重写方法--虚方法
        public override void Attack()
        {
            Console.WriteLine("{0}丢了一块石头",this.name);
        }
    }

    class Boss : Monster
    {
        public Boss(string name) : base(name)
        {
            attack = MonsterManage.r.Next(200, 501);
        }

        public override void Attack()
        {
            Console.WriteLine("{0}挥舞了狼牙棒",this.name);
        }
    }

}
